/**
 * ReportGear(2011)
 */
package com.reportgear.report.model.cell.value.salary;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import com.reportgear.report.core.api.idname.DefaultIdName;
import com.reportgear.report.core.api.idname.IdName;
import com.reportgear.report.model.cell.value.AbstractCellObject;
import com.reportgear.report.model.cell.value.ModelDesignableValueObjectClassManager;

/**
 * 薪酬档案信息
 * 
 * @version 1.0 2011-6-5
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class SalaryDocObject extends AbstractCellObject {
	private static List<IdName<String>> info = new ArrayList<IdName<String>>();

	static {
		info.add(new DefaultIdName<String>("objectID", "id"));
		info.add(new DefaultIdName<String>("deptName", "成本中心(组织机构)"));
		info.add(new DefaultIdName<String>("code", "员工编码"));
		info.add(new DefaultIdName<String>("personName", "员工姓名"));
		info.add(new DefaultIdName<String>("idCard", "身份证"));
		info.add(new DefaultIdName<String>("positionName", "职位"));
	}

	// 获取所有对象信息
	public static List<IdName<String>> getAllObjectInfo() {
		return info;
	}

	// 字段名
	private String field;
	// 名称
	private String name;

	public SalaryDocObject() {
		this.field = "objectID";
		this.name = "id";
	}

	@Override
	public String toString() {
		return this.name;
	}

	/**
	 * 设置字段名
	 * 
	 * @param field
	 *            字段名
	 */
	public void setField(String field) {
		this.field = field;
	}

	/**
	 * 获取字段名
	 * 
	 * @return 字段名
	 */
	public String getField() {
		return field;
	}

	/**
	 * 设置名称
	 * 
	 * @param name
	 *            名称
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 获取名称
	 * 
	 * @return 名称
	 */
	public String getName() {
		return name;
	}

	@Override
	public void read(Element parent) {
		this.field = parent.elementTextTrim("field");
		this.name = parent.elementTextTrim("name");
	}

	@Override
	public void write(Element parent) {
		parent.addAttribute("class", ModelDesignableValueObjectClassManager.INSTANCE.getClassKey(this.getClass()));

		Element el = parent.addElement("field");
		el.addText(String.valueOf(this.field));

		el = parent.addElement("name");
		el.addText(this.name);
	}
}
